<template>
  <PtDashBoard :layOut="layOut" @addBoard="addBoard">
  </PtDashBoard>
</template>

<script>

  export default {
    name: 'dashboard',
    components: {},
    data() {
      return {layOut: []}
    },
    mounted() {
      this.doQuery()
    },
    methods: {
      doQuery() {
        let url = "/login/auth/AuthBoard/findMy"
        if (this.isDefaultSets) {
          url = "/login/auth/AuthBoard/findDefault"
        }
        this.$http.post(url).then(response => {
          let boardData = response.data
          for (let i = 0; i < boardData.length; i++) {
            let oneBoard = boardData[i]
            oneBoard.urlImport = () => import('@/views/' + oneBoard.urlPath + ".vue")
            oneBoard.i = i
          }
          this.layOut = boardData
        })
      },
      addBoard(one) {
        let num = this.layOut.length
        let board = {}
        if (num != 0) {
          let lastLayout = this.layOut[num - 1]
          board.i = lastLayout.i + 1
          board.y = lastLayout.y + lastLayout.h //y为上下
        } else {
          board.i = 1
          board.y = 0
        }

        board.x = 0
        board.w = 24
        board.h = 6
        board.title = one.text
        board.urlImport = () => import('@/views/' + one.url + ".vue")
        board.menuId = one.id
        this.layOut.push(board)
      }
    },
    created() {
    },
  }
</script>
